const jwt = require('jsonwebtoken');
const {
    PRIVATE_KEY
} = require('../config/screct')

class LoginController {
    sign(ctx, next) {
        const {
            id,
            name
        } = ctx.user

        const token = jwt.sign({
            id,
            name
        }, PRIVATE_KEY, {
            expiresIn: '2 days',
            algorithm: "RS256"
        });
        ctx.body = {
            id,
            name,
            token
        }
    }

    test(ctx,next) {
        ctx.body = {
            cade: 200,
            result: '请求成功'
        }
    }
}

module.exports = new LoginController()